cmake_minimum_required(VERSION 3.5)

project(qcustomPlot LANGUAGES CXX)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

#用来编译ui文件
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

#指定输出目录
# set(OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../bin)
# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${OUTPUT_PATH})
# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${OUTPUT_PATH})
# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${OUTPUT_PATH})
# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${OUTPUT_PATH})

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# QtCreator supports the following variables for Android, which are identical to qmake Android variables.
# Check http://doc.qt.io/qt-5/deployment-android.html for more information.
# They need to be set before the find_package(Qt5 ...) call.

#if(ANDROID)
#    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
#    if (ANDROID_ABI STREQUAL "armeabi-v7a")
#        set(ANDROID_EXTRA_LIBS
#            ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libcrypto.so
#            ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libssl.so)
#    endif()
#endif()

set(Qt_pkg 
	Widgets 
	LinguistTools 
	Multimedia
	PrintSupport
)

find_package(QT NAMES Qt6 Qt5 COMPONENTS ${Qt_pkg} REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS ${Qt_pkg} REQUIRED)

set(TS_FILES qcustomPlot_zh_CN.ts)

# 设定自定义库路径
set(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/lib)
link_directories(${LIBRARY_OUTPUT_PATH})
#资源文件
set(QRC_FILES
    pic.qrc
)
qt5_add_resources(QRC_HEADERS ${QRC_FILES})

# qt_add_resources(QRC_FILES ${QRC_SOURCE_FILES})
# SOURCE_GROUP("Resource Files" FILES ${QRC_SOURCE_FILES})

# if(ANDROID)
#   add_library(qcustomPlot SHARED
#     main.cpp
#     mainwindow.cpp
#     mainwindow.h
#     mainwindow.ui
#     ${TS_FILES}
#   )
# else()

# 查找cpp文件
# set(SRC_LIST test.cpp)
# aux_source_directory(${PROJECT_SOURCE_DIR} SRC)
file(GLOB SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp) 

# 查找ui文件,设定CMAKE_AUTOUIC_SEARCH_PATHS的路径，
# 自动查找.ui文件，解决.cpp和.ui不在同一个目录的问题
file(GLOB UI_FILES ${CMAKE_CURRENT_SOURCE_DIR}/ui/*.ui)
# file(GLOB UI_INCLUDE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/ui/*.h)
set(CMAKE_AUTOUIC_SEARCH_PATHS ${CMAKE_CURRENT_SOURCE_DIR}/ui)

# 查找头文件
file(GLOB INCLUDE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h)
list(REMOVE_ITEM INCLUDE_FILES 
    ${CMAKE_CURRENT_SOURCE_DIR}/include/test.h
)

# 引入头文件
include_directories(
	${CMAKE_CURRENT_SOURCE_DIR}/include
	${CMAKE_CURRENT_SOURCE_DIR}/ffmpeg
)
# # 生成ui文件对应的头文件
# qt5_wrap_ui(UI_HEADERS ${UI_FILES})

# 设置可执行文件输出路径
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/bin)

# message(inc: ${INCLUDE_FILES})
# message(INCLUDE_FILES:${INCLUDE_FILES})
add_executable(qcustomPlot


	${SRC_FILES}
	${UI_FILES}
	${INCLUDE_FILES}

	# ${UI_HEADERS}
    ${QRC_HEADERS}
    ${TS_FILES}

	ffmpeg/ffmpeg.h
	ffmpeg/ffmpeg.cpp
)
# endif()

target_link_libraries(qcustomPlot 
    Qt${QT_VERSION_MAJOR}::Widgets
    Qt${QT_VERSION_MAJOR}::Multimedia
    Qt${QT_VERSION_MAJOR}::PrintSupport
    #avcodec
    avcodec 
    #av_dict
    avformat avutil  
    # sws_scale
    swresample swscale
)

qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})

# message("CMAKE_SOURCE_DIR" ${CMAKE_SOURCE_DIR})
qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
qt5_create_translation(QM_FILES ${TS_FILES} ${CMAKE_SOURCE_DIR} )


# if(WIN32)
# set(Qt5_DIR "F:\\Qt\\Qt5.12.10\\5.12.10\\mingw73_64\\lib\\cmake\\Qt5")
# get_target_property(Qt5Core_location Qt5::Core LOCATION)
# message(STATUS "Qt5 Core file: ${Qt5Core_location}")

# #message(STATUS "Qt5 Core file: $<TARGET_FILE:Qt5::Core>")
# add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
#      COMMAND ${CMAKE_COMMAND} -E copy_if_different
#      $<TARGET_FILE:Qt5::Core> $<TARGET_FILE_DIR:${PROJECT_NAME}>
#      # $<TARGET_FILE:Qt5::Gui> $<TARGET_FILE_DIR:${PROJECT_NAME}>
#      $<TARGET_FILE:Qt5::Widgets> $<TARGET_FILE_DIR:${PROJECT_NAME}>
# )
# add_custom_command(TARGET ${PROJECT_NAME} PRE_BUILD
#      COMMAND ${CMAKE_COMMAND} -E copy_directory
#      ${Qt5_DIR}/../../../plugins/platforms $<TARGET_FILE_DIR:${PROJECT_NAME}>/platforms
#      # ${TS_FILES} $<TARGET_FILE_DIR:${PROJECT_NAME}>
# )
# endif()


